<template>
	<view>
		<view class="lb-main-32" style="padding-bottom: 140rpx;">
			<u-empty v-if="listData.length < 1" mode="data" text="暂无数据" icon="/static/empty/data.png"></u-empty>
			<view class="lb-ad" v-for="(item,index) in listData" :key="index">
				<view class="ad-img">
					<image :src="getImgUrl(item.goods_info.cover_image)" mode="aspectFill"></image>
				</view>
				<view class="ad-info">
					<view class="ad-name u-line-2">
						{{item.goods_info.name}}
					</view>
					<view class="ad-price">
						<text>¥</text>
						{{item.goods_info.price}}
						<text v-if="item.amount">任洗{{item.goods_info.amount}}件</text>
					</view>
					<button open-type="share" :data-id="item.goods_info.id" :data-name="item.goods_info.name"
						:data-img="item.goods_info.cover_image">
						<view class="ad-btn">
							<image src="/static/icon/share-f.png" mode=""></image>立即分享
						</view>
					</button>
				</view>
			</view>

		</view>
		<view class="lb-foot">
			<view class="lb-btn" @click="goTo('/pages/xi-hu/promotion/detail')">
				推广明细
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getPromotionApiList
	} from "@/api/apis/wash.js"
	import {
		setImgUrl
	} from "@/utils/comm.js"
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				listData: [],
				isLoading: false
			}
		},
		onReachBottom() {
			//注意 这里是重要的一步，不满足条件下拉加载不能继续请求数据
			if (!this.isLoading) {
				this.getList();
			}

		},
		methods: {
			goTo(url) {
				if (url) {
					uni.navigateTo({
						url: url
					})
				}
			},
			//
			getImgUrl(url) {
				return setImgUrl(url);
			},
			//列表
			getList() {
				uni.showLoading({
					title: "加载中",
					mask: true
				});
				this.isLoading = true;
				getPromotionApiList({
					// is_recommend: 1,
					page: this.page,
					limit: this.limit,
				}).then(res => {
					uni.hideLoading();
					if (this.page == 1) {
						this.listData = res.data.data;
					} else {
						this.listData = this.listData.concat(res.data.data);
					}
					if (res.data.total > this.page * this.limit) {
						// console.log(res.data.length)
						//请求成功 节流阀 设置为false（没有走完函数不允许再次请求）
						this.isLoading = false;
						this.page++;
					}
				})
			},
		},
		//分享
		//onShareAppMessage 分享给朋友
		//onShareTimeline  分享到朋友圈
		// #ifdef MP
		onShareAppMessage: function(res) {
			let that = this;
			if (res.from === 'button') {
				// 来自页面内转发按钮
				console.log(res.target, '++++')
				console.log(that.user_info, '----')
				let dataset = res.target.dataset;
				let gName = dataset.name;
				let img = setImgUrl(dataset.img);
				let gid = dataset.id;
				let uid = that.user_info.id;
				return {
					title: gName,
					imageUrl: img,
					path: '/pages/xi-hu/goods-detail/goods-detail?did=' + uid + '&id=' + gid,
				}
			}
		},
		onShareTimeline: function(res) {
			let that = this;
			if (res.from === 'button') {
				// 来自页面内转发按钮
				console.log(res.target, '----')
				console.log(that.user_info, '----')
				let dataset = res.target.dataset;
				let gName = dataset.name;
				let img = setImgUrl(dataset.img);
				let gid = dataset.id;
				let uid = that.user_info.id;
				return {
					title: gName,
					imageUrl: img,
					path: '/pages/xi-hu/goods-detail/goods-detail?did=' + uid + '&id=' + gid,
				}
			}

		},
		// #endif
		onLoad() {
			this.getList();
		}
	}
</script>

<style lang="scss">
	//底部
	.lb-foot {
		width: 100%;
		height: 120rpx;
		background: rgba(255, 255, 255, 1);
		box-shadow: 0rpx -1rpx 0rpx rgba(0, 0, 0, 0.3);
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		align-items: center;
		justify-content: center;
		.lb-btn {
			width: 600rpx;
			height: 88rpx;
			background: linear-gradient(134deg, #F7583F 0%, #F28F4C 100%);
			border-radius: 44rpx;
			font-size: $main-font-28;
			line-height: 86rpx;
			text-align: center;
			color: $main-font-color-white;
		}
	}

	button::after {
		border: none;
	}

	button {
		margin: 0;
		padding: 0;
		outline: none;
		border-radius: 0;
		background-color: transparent;
		line-height: inherit;
	}

	button:hover {
		background: none;
	}

	.lb-ad {
		background: rgba(255, 255, 255, 0.39);
		box-shadow: 0rpx 2rpx 4rpx rgba(0, 0, 0, 0.16);
		opacity: 1;
		border-radius: 16rpx;
		display: flex;
		flex-direction: row;
		margin-bottom: 24rpx;

		.ad-img {
			width: 456rpx;
			height: 300rpx;

			image {
				width: 100%;
				height: 100%;
				border-radius: 16rpx 0 0 16rpx;

			}
		}

		.ad-info {
			width: calc(100% - 456rpx);
			display: flex;
			flex-direction: column;
			justify-content: space-evenly;
			padding: 24rpx;

			.ad-name {
				font-size: $main-font-24;
				font-weight: bold;
				color: #666666;
			}

			.ad-price {
				font-size: 36rpx;
				font-family: DIN;
				font-weight: bold;
				color: #2F2D2E;

				text {
					font-size: $main-font-20;
					font-weight: 400;
					color: #171717;
					margin-right: 4rpx;

					&:nth-of-type(3n-1) {
						font-size: $main-font-18;
						font-weight: 400;
						color: #666666;
						margin-left: 12rpx;
						margin-right: 0;
					}
				}
			}

			.ad-btn {
				border: 2rpx solid #F67F7D;
				width: 156rpx;
				height: 48rpx;
				background: linear-gradient(106deg, #F7583F 0%, #F28F4C 100%);
				border-radius: 24rpx;
				font-size: 24rpx;
				font-weight: 400;
				color: #FFFFFF;
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;

				image {
					width: 28rpx;
					height: 28rpx;
					margin-right: 4rpx;
				}

			}


		}

	}
</style>